From: Aki Tuomi Date: Mon, 26 Jan 2026 07:47:16 +0000 (+0200) Subject: [PATCH] lib-regex: Do not use data stack for replacement string X-Git-Tag: archive/raspbian/1%2.4.2+dfsg1-3+rpi1^2~1 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22%22/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22%22?a=commitdiff_plain;h=1bac2b97290bd022a5af839d7a43b487596aadf4;p=dovecot.git [PATCH] lib-regex: Do not use data stack for replacement string It will get lost when the data stack frame is dropped at the end, so use heap memory instead. Gbp-Pq: Name lib-regex-Do-not-use-data-stack-for-replacement-stri.patch --- diff --git a/src/lib-regex/regex.c b/src/lib-regex/regex.c index d48b48a..ade57eb 100644 --- a/src/lib-regex/regex.c +++ b/src/lib-regex/regex.c @@ -379,7 +379,7 @@ int dregex_code_replace_full(struct dregex_code *code, #endif } - PCRE2_UCHAR *result32 = U""; + PCRE2_UCHAR *result32 = NULL; PCRE2_SIZE result_len = 0; int ret; @@ -416,7 +416,7 @@ int dregex_code_replace_full(struct dregex_code *code, } if (result_len > 0) - result32 = t_new(PCRE2_UCHAR, result_len); + result32 = i_new(PCRE2_UCHAR, result_len); /* Run it again as we know the buffer size now */ code->climit = cpu_limit_init(code->max_cpu_seconds, @@ -428,10 +428,14 @@ int dregex_code_replace_full(struct dregex_code *code, pcre2_match_data_free(mdata); } while(0); T_END; - if (ret < 0) + if (ret < 0) { + i_free(result32); return handle_error(ret, error_r); - else if (ret > 0) + } else if (ret > 0) { + i_assert(result32 != NULL); uni_ucs4_to_utf8(result32, result_len, result_r); + i_free(result32); + } return ret > 0 ? 1 : 0; }